package org.bpms.controller.admin;

import java.util.HashMap;
import java.util.Map;

import org.bpms.interceptor.WebInterceptor;
import org.bpms.plugins.bjui.BjuiRender;
import org.bpms.service.admin.FaqService;

import com.jfinal.aop.Clear;
import com.jfinal.aop.Enhancer;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

/**
 * 问答控制器
 * @author hupei
 *
 */
@Clear(WebInterceptor.class)
public class FaqController extends Controller{
	private  FaqService faqService =  Enhancer.enhance(FaqService.class);
	
	
	/**
	 * 后台首页
	 */
	public void index(){
		Map<String,Object> pagemap = new HashMap<String, Object>();
		String tabid = getPara("tabid");
		Integer pageNumber = getParaToInt("pageCurrent", 1);//要访问第几页，默认1
		Integer pageSize = getParaToInt("pageSize", 15);//每页多少条数据，默认15
		String orderField = getPara("orderField", "ctime");//对什么字段排序，默认空字符串
		String orderDirection = getPara("orderDirection", "desc");//升序还是降序，默认升序
		String title = getPara("title" , "");
		String stime = getPara("stime" , "");
		String etime = getPara("etime" , "");
		int typeid = getParaToInt("typeid" , 0);
		faqService.findAllTop(title, typeid, stime, etime, pageNumber, 
				pageSize, orderField, orderDirection, pagemap);
		setAttr("page",pagemap);
		setAttr("title", title);
		setAttr("stime", stime);
		setAttr("etime", etime);
		setAttr("typeid", typeid);
		setAttr("tabid", tabid);
		render("/admin/faq/faq.html");
	}
	
	/**
	 * 查看回复
	 */
	public void child(){
		Map<String,Object> pagemap = new HashMap<String, Object>();
		String tabid = getPara("tabid");
		Integer pageNumber = getParaToInt("pageCurrent", 1);//要访问第几页，默认1
		Integer pageSize = getParaToInt("pageSize", 15);//每页多少条数据，默认15
		String orderField = getPara("orderField", "ctime");//对什么字段排序，默认空字符串
		String orderDirection = getPara("orderDirection", "desc");//升序还是降序，默认升序
		int id = getParaToInt("pid" , 0);
		faqService.findAllChi(id, "" , "" , pageNumber,
				pageSize, orderField, orderDirection, pagemap);
		setAttr("page",pagemap);
		setAttr("id", id);
		setAttr("tabid", tabid);
		render("/admin/faq/child.html");
	}
	
	/**
	 * 查看主题
	 */
	public void view(){
		String tabid = getPara("tabid");
		int id = getParaToInt("id" , 0);
		Record faq = faqService.findById(id);
		setAttr("tabid", tabid);
		setAttr("faq", faq);
		render("/admin/faq/info.html");
	}
	
	/**
	 * 查看回复主题
	 */
	public void childview(){
		String tabid = getPara("tabid");
		int id = getParaToInt("id" , 0);
		Record faq = faqService.findById(id);
		setAttr("tabid", tabid);
		setAttr("faq", faq);
		render("/admin/faq/childinfo.html");
	}
	
	/**
	 * 删除
	 */
	public void remove(){
		String details = getPara("delids" , "");
		String tabid = getPara("tabid");
		faqService.remove(details);
		render(BjuiRender.success("删除成功！" , false).tabid(tabid));
	}
	
}
